import config from "@/configs/device.config";
import {
  IdCard,
  Bcr,
  A4,
  Common,
  Cam,
  Prr,
  Glt,
  Pin,
  Fpc,
} from "@/ecjrts/mode";

export interface ModsInstance {
  IdCard?: IdCard;
  bcr?: Bcr;
  a4?: A4;
  cam?: Cam;
  face?: Cam;
  prr?: Prr;
  common?: Common;
  glt?: Glt;
  pin?: Pin;
  fpc?: Fpc;
}
let modsInstance: ModsInstance | null = null;

export const createWosaModule = function (qObjects: any): ModsInstance {
  modsInstance = {};
  if (qObjects.common)
    modsInstance.common = new Common("common", qObjects.common);
  for (let { deviceName } of config) {
    switch (deviceName) {
      case "IdCard":
        if (qObjects.IdCard)
          modsInstance.IdCard = new IdCard("IdCard", qObjects.IdCard);
        break;
      case "fpc":
        if (qObjects.fpc) modsInstance.fpc = new Fpc("fpc", qObjects.fpc);
        break;
      case "pin":
        if (qObjects.pin) modsInstance.pin = new Pin("pin", qObjects.pin);
        break;
      case "glt":
        if (qObjects.glt) modsInstance.glt = new Glt("glt", qObjects.glt);
        break;
      case "bcr":
        if (qObjects.bcr) modsInstance.bcr = new Bcr("bcr", qObjects.bcr);
        break;
      case "prr":
        if (qObjects.rec) modsInstance.prr = new Prr("prr", qObjects.rec);
        break;
      case "cam":
        if (qObjects.cam) modsInstance.cam = new Cam("cam", qObjects.cam);
        break;
      case "face":
        if (qObjects.facecam)
          modsInstance.face = new Cam("face", qObjects.facecam);
        break;
      case "a4":
        if (qObjects.a4) modsInstance.a4 = new A4("a4", qObjects.a4);
        break;
      default:
        break;
    }
  }
  return modsInstance;
};

export const useModule = function (): ModsInstance {
  if (modsInstance) {
    return modsInstance;
  }
  throw new Error("you not createModule");
};
